package team.pwy.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import team.pwy.consts.RbmConsts;
import team.pwy.pojo.entity.Member;
import team.pwy.pojo.entity.Vip;
import team.pwy.service.MemberService;
import team.pwy.service.VipService;
import team.pwy.vo.Result;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    private VipService vipService;
    @Autowired
    private MemberService memberServer;
    @Autowired
    private RedisTemplate redisTemplate;

//    @Autowired
//    private RabbitTemplate rabbitTemplate;

    @GetMapping("price")
    public Result findAll(){
        Vip vip = vipService.findAll();
        return new Result("200","查询成功",vip);
    }

    //根据用户id查询会员状态
    @GetMapping("/findByUserId/{id}")
    public Result findByUserId(@PathVariable("id") Integer userId) {
        System.out.println(userId);
        Member member = memberServer.findByUserId(userId);
        System.out.println(member);
        if (member.getStatus() == 0) {
            return new Result("500", "你还未开通会员",member);
        } else if (member.getStatus()==2){
            return new Result("505","会员已过期",member);
        }
        return new Result("200","已开通会员",member);
    }

//    @PostMapping ("{userId}/{secId}")
//    public Result member(@PathVariable("userId") Integer userId,@PathVariable("secId") Integer secId){
//        Map<String, Integer> maps = new HashMap<>();
//        maps.put("userId", userId);
//        maps.put("secId", secId);
//        rabbitTemplate.convertAndSend(RbmConsts.MEMBER_QUEUE,maps);
//        if (secId==0){
//            return new Result("200","开通成功");
//        } else if (secId==1) {
//            return new Result("200","续费成功");
//        }else {
//            return new Result("200","重新开通成功");
//        }
//    }

}